import axios from 'axios';
import { instance } from "../axios";
import { getMockData } from "./mockData";

// 获取用户消息列表
export const getMessages = (userId) => {
  return instance.get(`/api/messages/${userId}`);
};

// 发送新消息
export const sendMessage = (receiverId, content) => {
  return instance.post('/api/messages/send', { receiverId, content });
};

// 标记消息为已读
export const markAsRead = (messageId) => {
  return instance.put(`/api/messages/read/${messageId}`);
};

// 删除消息
export const deleteMessage = (messageId) => {
  return instance.delete(`/api/messages/${messageId}`);
};

// 模拟获取用户消息列表
export const getMockMessages = (userId) => {
  console.log('getMockMessages 被调用，参数:', userId);
  return getMockData('messages', userId);
};

// 模拟发送消息
export const sendMockMessage = (receiverId, content) => {
  console.log('sendMockMessage 被调用，参数:', { receiverId, content });
  // 简单模拟发送成功
  return { 
    data: { 
      success: true, 
      message: '消息发送成功', 
      data: {
        id: 'msg' + Date.now(),
        sender: localStorage.getItem('id') || 'ccb123',
        receiver: receiverId,
        content,
        time: new Date().toISOString().replace('T', ' ').substring(0, 16),
        read: false
      }
    }
  };
}; 